#coding=utf-8
import gtk
from stockdb.misc import *

date = '2008-03-17'

ss = sess.query(Stock).all()[:10]
data = []

for s in ss:
    td = s.find_td(date)
    if not td:continue
    
    p = td.price
    d = [date, s.code, s.name, td.close, p.change, p.trade_rate]
    data.append(d)

lt = gtk.ListStore(str, str, str, str, str, str)
for d in data:
    lt.append(d)

tv = gtk.TreeView(lt)
column_head = ['交易日', '代码', '名称', '收盘价', '涨幅', '换手率']

i = 0
for h in column_head:

    cell = gtk.CellRendererText()
    tc = gtk.TreeViewColumn(h)
    
    tc.pack_start(cell, True)
    tc.add_attribute(cell, 'text', i)
    
    tv.append_column(tc)
    
    i = i + 1
    
window = gtk.Window()
window.add(tv)
window.show_all()

gtk.main()
